package com.orhon.smartcampus.modules.teacher.fetcher;

import com.orhon.smartcampus.auth.JwtUtils;
import com.orhon.smartcampus.modules.user.dao.TokenService;
import com.orhon.smartcampus.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.orhon.smartcampus.modules.teacher.dao.TeamBuildingDao;
import com.orhon.smartcampus.modules.teacher.entity.TeamBuilding;
import com.orhon.smartcampus.modules.teacher.gqlModel.GQLTeamBuilding;
import com.orhon.smartcampus.modules.teacher.mm.TeamBuildingMapper;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;

@Component
public class TeamBuildingFetcher implements DataFetcher  {
	
	@Autowired
    TeamBuildingDao teamBuildingDao;

    @Autowired
    TokenService tokenService;

    @Override
    public Object get(DataFetchingEnvironment env) throws Exception {
        String token = tokenService.getSystemToken();
        if(token==null) {
            return  R.NoLogin();
        }
        Long schoolId = JwtUtils.getSchoolId(token);

        int id = Integer.parseInt(env.getArgument("id").toString());

        String hql = "from TeamBuilding where deleted_at = null and id = "+id+" and school_id = " + schoolId;
        TeamBuilding item =  teamBuildingDao.findId(hql, null);
        if(item!=null) {
            GQLTeamBuilding mapEntity = TeamBuildingMapper.MAPPER.mapEntity(item);
            return mapEntity;
        }
		return null;
        
    }
}
